package com.wh.base.font;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import com.wh.base.sys.config.service.ConfigService;
import com.wh.base.sys.user.service.UserService;
import com.wh.base.util.RedisUtil;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 部分前端页面控制
 * </p>
 *
 * @author WangHong
 */
@Controller
public class PageController {
	
	@Autowired
	private ConfigService configService;
	
	@Autowired
	private UserService userService;
	
	@Resource
    private RedisUtil redisUtil;
	
	@GetMapping("/login")
	@ApiOperation(value = "登录页面")
	public String login(){
		//如果已登录则直接跳转首页
		if(StpUtil.isLogin()) {
			return "redirect:/";
		}
		return "auth/login";
	}
	
	@GetMapping("/")
	@ApiOperation(value = "首页")
	@SaCheckLogin
	public String index(Model model){
		
		model.addAttribute("systemName", configService.cfg().get("system.name")); //系统名称
		model.addAttribute("logoName", configService.cfg().get("system.logo.name")); //logo名称
		model.addAttribute("username", userService.getUser().getUsername());  //用户名
		model.addAttribute("menuJson", redisUtil.get("user_menu_"+StpUtil.getLoginIdAsLong()));  //用户菜单
		
		return "index";
	}
	
	@GetMapping("/font/main")
	@ApiOperation(value = "消息页面")
	public String main(Model model){
		model.addAttribute("systemName", configService.cfg().get("system.name")); //系统名称
		return "global/main";
	}
	
	@GetMapping("/font/modify")
	@ApiOperation(value = "修改密码页面")
	@SaCheckLogin
	public String modify(){
		return "auth/modify";
	}
	
	@GetMapping("/font/theme")
	@ApiOperation(value = "主题页面")
	public String theme(){
		return "global/theme";
	}
	
	@GetMapping("/font/lockScreen")
	@ApiOperation(value = "锁屏页面")
	public String lockScreen(){
		return "global/lockScreen";
	}
	
	@GetMapping("/font/note")
	@ApiOperation(value = "标签页面")
	public String note(){
		return "global/note";
	}
	
	@GetMapping("/font/message")
	@ApiOperation(value = "消息页面")
	public String message(){
		return "global/message";
	}
}
